import cv2
import numpy as np

img = cv2.imread("C:\\Users\\86191\\Pictures\\Saved Pictures\\Camera Roll\\shudu.jpg")
i = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
i = np.float32(i)
# Harris角点检测
dst = cv2.cornerHarris(i, 2, 3, 0.03)
kernel = np.ones((3,3),np.uint8)
dst = cv2.dilate(dst,kernel)
img[dst>0.01*dst.max()]=[0,0,255]
cv2.imshow("dst",img)
cv2.waitKey(0)

# import numpy as np
# import cv2 as cv
# filename = "C:\\Users\\86191\\Pictures\\Saved Pictures\\Camera Roll\\shudu.jpg"
# img = cv.imread(filename)
# gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
# # 寻找哈里斯角
# gray = np.float32(gray)
# dst = cv.cornerHarris(gray,2,3,0.04)
# dst = cv.dilate(dst,None)
# ret, dst = cv.threshold(dst,0.01*dst.max(),255,0)
# dst = np.uint8(dst)
# # 寻找质心
# ret, labels, stats, centroids = cv.connectedComponentsWithStats(dst)
# # 定义停止和完善拐角的条件
# criteria = (cv.TERM_CRITERIA_EPS + cv.TERM_CRITERIA_MAX_ITER, 100, 0.001)
# corners = cv.cornerSubPix(gray,np.float32(centroids),(5,5),(-1,-1),criteria)
# # 绘制
# res = np.hstack((centroids,corners))
# res = np.intp(res)
# img[res[:,1],res[:,0]]=[0,0,255]
# img[res[:,3],res[:,2]] = [0,255,0]
# cv.imwrite('subpixel5.png',img)
